package com.happy.second;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

@EnableDiscoveryClient
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@ComponentScan(basePackages = {"com.happy"})
@EnableTransactionManagement
public class SecondApplication {

    @Bean
    public PlatformTransactionManager prodTransactionManager(@Qualifier("qlpData") DataSource prodDataSource) {
        return new DataSourceTransactionManager(prodDataSource);
    }

    @Bean
    public PlatformTransactionManager devTransactionManager(@Qualifier("ynnData") DataSource sitDataSource) {
        return new DataSourceTransactionManager(sitDataSource);
    }

    public static void main(String[] args) {
        SpringApplication.run(SecondApplication.class, args);
    }


}
